package by.ins.webconsole;


import java.rmi.RemoteException;
import java.rmi.registry.Registry;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.directwebremoting.annotations.RemoteMethod;
import org.directwebremoting.annotations.RemoteProxy;

import by.ins.app.AppContext;
import by.ins.app.commands.AppCommandConstants;
import by.ins.app.commands.AppCommnandProvider;
import by.ins.app.console.RemoteAdminConsoleImpl;
import by.ins.life.evolution.ILifeEvoluter;
import by.yativem.commons.console.ConsoleCommandBean;

@RemoteProxy(name = "ins")
public class WEBRemoteConsole {
private static final Logger log = LogManager.getLogger(WEBRemoteConsole.class);
	private static Registry registry;
	private static RemoteAdminConsoleImpl server;
	
	private AppCommnandProvider appCommnandProvider;
	
	protected AppCommnandProvider getAppCommnandProvider(){
		if(appCommnandProvider == null){
			appCommnandProvider = AppContext.getAppCommnandProvider();
		}
		return appCommnandProvider;
	}


	@RemoteMethod
	public String callTest() {
		return "Hello;";
	}

	@RemoteMethod
	public String startIns() {
		return "Hello;";
	}

	@RemoteMethod
	public boolean isInsStarted() {
		

		return false;
	}

	@RemoteMethod
	public ILifeEvoluter[] getLifes() throws RemoteException {
		log.error("Hi eee");
		ILifeEvoluter[] result = null;
		try {
			
			 result = (ILifeEvoluter[]) getAppCommnandProvider().sendCommand(
					new ConsoleCommandBean(
							AppCommandConstants.COMMAND_LIFEEVOLUTOR));
		} catch (Exception e) {
			log.error("", e);
		}
		return result;
	}

}
